package Model;

import util.Player;
import util.TicTacToeException;

public class Game {
	
	//var
	
	Board theboard;
	public Player currentPlayer;
	Player winner;
	
	//con
	
	public Game() {
		
		initialize();
		
		
	}
	
	
	//meth
	
	
	public void initialize() {
		theboard = new Board();
		currentPlayer = Player.X;
		winner = null;
		
	} 
	
	
	public void makeMove(int x, int y) throws TicTacToeException {
			
		if(winner!=null){
			throw new TicTacToeException("Stop trying to win! You already lost!");
		}
		
			
			theboard.makeMove(x, y, currentPlayer);
			
			//code if move is good
			
			if(currentPlayer==Player.O) {
				currentPlayer=Player.X;
			} else if(currentPlayer==Player.X) {
				currentPlayer = Player.O;
			}
			//win code

			if(theboard.checkWin(currentPlayer) != null) {
				System.out.println("Player " + currentPlayer + " wins!");
				winner = currentPlayer;
				
			}
				
	}
	
	
	public void printBoard() {
		theboard.printBoard();
	}
	
	
	
}
